<?php
class contactActions extends myFrontendAction{

  public function preExecute()
  {
    $this->form = new SimpleContactForm();
  }

  public function executeSubmit(sfRequest $request)
  {
    $this->form->bind($request->getParameter($this->form->getName()));
    
    if($this->form->isValid())
    {
      $this->getMailer()->composeAndSend('feedback@enermaatik.ee', 'info@enermatik.ee', 'Tagasiside',
        'Tere, teile tuli tagasiside:'."\n".
        implode("\n",$this->form->getValues()));
      $this->renderPartial('global/json', array('item' => array(
              'code' => 200,
              'notice' => __('Andmed edukalt saadetud')
      )));      
    } 
    else
    {
      $this->renderPartial('global/json', array('item' => array(
              'code' => 500,
              'errors' => $this->form->getErrors()
      )));
    }

    return sfView::NONE;
  }
}